package com.tg.demo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tg.demo.entity.Score;
import com.tg.demo.mapper.ScoreMapper;
import com.tg.demo.service.ScoreService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * 用户信息表ServiceImpl
 *
 * @author yuanjin
 */
@Service
public class ScoreServiceImpl implements ScoreService {
    private static final Logger logger = LoggerFactory.getLogger(ScoreServiceImpl.class);

    @Resource
    private ScoreMapper scoreMapper;

    @Override
    public Score getByUserCode(String userCode) {
        List<Score> list = scoreMapper.getListByCondition(
                Score.builder().userCode(userCode).build()
        );
        if (null != list && !list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public PageInfo<Score> getListByPage(Score score, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        List<Score> list = scoreMapper.getListByCondition(score);
        return PageInfo.of(list);
    }
}
